#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/4/21 21:44
# @Author  : Grayson Liu
# @Email   : graysonliu@foxmail.com
# @File    : GraphicPreProcessWizardDialog.py

from PyQt5.QtWidgets import QDialog, QFileDialog

from ui.Ui_GraphicPreProcessWizardDialog import Ui_GraphicPreProcessWizardDialog
from CustomSignal import CustomSignal


class GraphicPreProcessWizardDialog(QDialog, Ui_GraphicPreProcessWizardDialog):
    """
    设置遥感影像预处理的对话框
    """
    global_signal = CustomSignal()

    def __init__(self, preprocess_dic: dict, parent=None):
        """
        初始化
        :param preprocess_dic: 从ProjectForm传递而来的预处理信息
        :param parent: 父窗体
        """
        super(GraphicPreProcessWizardDialog, self).__init__(parent)
        self.setupUi(self)

        # 把传入字典的内容显示在窗体上
        if preprocess_dic["nan_process"] == "zero":
            self.radioNanZero.setChecked(True)
        elif preprocess_dic["nan_process"] == "mean":
            self.radioNanMean.setChecked(True)
        else:
            self.radioNanNone.setChecked(True)
        if preprocess_dic["anomaly_process"] == "three_sigma":
            self.radioAnomalyThreeSigma.setChecked(True)
        else:
            self.radioAmomalyNone.setChecked(True)

        # TODO: 绑定信号和槽
        self.btnConfirm.clicked.connect(self.confirm_preprocess)

    def confirm_preprocess(self):
        """
        对话框“确认”按钮的槽函数
        :return:
        """
        preprocess_dic = {}
        if self.radioNanZero.isChecked():
            preprocess_dic["nan_process"] = "zero"
        elif self.radioNanMean.isChecked():
            preprocess_dic["nan_process"] = "mean"
        else:
            preprocess_dic["nan_process"] = "none"
        if self.radioAnomalyThreeSigma.isChecked():
            preprocess_dic["anomaly_process"] = "three_sigma"
        else:
            preprocess_dic["anomaly_process"] = "none"
        # 给主窗体发信号，把信息发送给ProjectForm进行处理
        GraphicPreProcessWizardDialog.global_signal.set_preprocess.emit(preprocess_dic)
        self.close()
